///TITLE: Examining public support for comprehensive policy packages to tackle unhealthy food environments*****

clear all
 import delimited "/Users/simone/Downloads/Day 2/Exercise/Stata/WP1.1 Final Survey (Only Completes, Concat).csv", delimiter(comma)
 
drop if durationinseconds < 600 // Drop participants who take less than 10 minutes to complete (speeders)
drop if (age==.&gender==.)

****Expansion 1, manual expand****

*define globals*
global supporta_task support_1a support_2a support_3a support_4a support_5a support_6a support_7a support_8a support_1b support_2b support_3b support_4b support_5b support_6b support_7b support_8b
rename support_1a support1
rename support_2a support2
rename support_3a support3 
rename support_4a support4 
rename support_5a support5 
rename support_6a support6 
rename support_7a support7  
rename support_8a support8 
rename support_1b support9
rename support_2b support10
rename support_3b support11 
rename support_4b support12 
rename support_5b support13 
rename support_6b support14 
rename support_7b support15  
rename support_8b support16 

**generate unique id for each participant 
generate id= _n

**generate block**
generate block=0 if(support5==.)
replace block=1 if (support1==.)

**reshape 
reshape long support, i(id) j(task) // 


***************************Coding of choice set attributes according choice set design***************************

**attribute 1 - nutrition standards in kindergartens and schools (KS)**
sort id task  
egen KS=fill(1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1)

**attribute 2 - VAT increase (VATinc)**
sort id task
egen vatinc=fill(1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 0)

**attribute 3 - VAT dec (VATdec)**
sort id task
egen vatdec=fill(1 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0)

**attribute 4 - SSB tax (tax)**
sort id task
egen tax=fill(0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 )

**attribute 5 - nutrtion standards in public institutions (public)**
sort id task
egen public=fill(1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 1 )

**attribute 6 - action plan on drinking water (water) **
sort id task
egen water=fill(0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1)

**attribute 7 - nutrition education in kindergartens and schools **
sort id task
egen nuted=fill(1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 )

****block A or block B*******
sort id task
egen block_A=fill(1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0) //this will be control variable in the linear regrssion to show that support for a given policy was not dependent on whether the policy was presented in policy package A or in policy package B 


********LINEAR REGRESSION ON SUPPORT AS CONTINUOUS VARIABLE*****

xtset id task //telling model it is panel data 
xtreg support vatinc tax public KS water nuted vatdec block_A, fe //we use the fixed effects linear regression model because there is no variation in the explanatory variables between individuals, so there should not be between variation, which we see is true (R squared for between = 0.0013); This code also includes robust standard error for panel data
*****Generating margins plot****
est sto support_model
margins, dydx (vatinc tax public KS water nuted vatdec ) 
marginsplot

marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal
//Note: We looked at the distribution (asymptotically normal distribution can be assumed from the data - phrase in order to justify that we can use a linear regression model)
esttab support_model using hypotheses3.rtf, se label replace


 ***This model is pretty finalized*** 
 ** block A is controlled for so we do not need to include it in final visualization, but maybe should note it 
 **Important conclusion is that it is the combination of many policies that garners support, not just single ones (caveat: we have not measured interaction effects)
 
 
 ********LOGIT MODEL ON SUPPORT AS BINARY VARIABLE*****

 
******generating binary support dummy variable****
gen dummysupport = 0 if support < 5 & support != .
replace dummysupport = 1 if support > 4 & support != .

logistic dummysupport vatinc tax water public KS nuted vatdec block_A, 


//MIXED LOGIT MODEL
xtset id task
xtlogit dummysupport vatinc tax water public KS nuted vatdec block_A, fe or
margins, dydx (vatinc tax water public KS nuted vatdec) //
marginsplot, xline(0) recast(scatter) recastci(rspike) horizontal
esttab dummysupport_model using dummysupport.rtf, se label replace



